
/// 首页数据的model层
// ConfigModel config | Object	| NonNull
//`List<CommonModel>` bannerList | Array	|	NonNull
//`List<CommonModel>` localNavList | Array	| NonNull
// GridNavModel gridNav | Object	|	NonNull
//`List<CommonModel>` subNavList | Array	|	NonNull
// SalesBoxModel salesBox | Object	|	NonNull
class HomeModel {

  final ConfigModel config;
  final List<CommonModel> bannerList;
  final List<CommonModel> localNavList;
  final GridNavModel gridNav;
  final List<CommonModel> subNavList;
  final SalesBoxModel salesBox;
  HomeModel({this.config, this.bannerList, this.localNavList, this.gridNav, this.subNavList, this.salesBox});

  factory HomeModel.fromJson(Map<String,dynamic>json) {
    var bannerListJson = json['bannerList'] as List;
    List<CommonModel> bannerList = bannerListJson.map((e) => CommonModel.fromJson(e)).toList();
    var localNavListJson = json['localNavList'] as List;
    List<CommonModel> localNavList = localNavListJson.map((e) => CommonModel.fromJson(e)).toList();
    var subNavListJson = json['subNavList'] as List;
    List<CommonModel> subNavList = subNavListJson.map((e) => CommonModel.fromJson(e)).toList();

    return HomeModel(
      bannerList: bannerList,
      localNavList: localNavList,
      subNavList: subNavList,
      config: ConfigModel.fromJson(json['config']),
      gridNav: GridNavModel.fromJson(json['gridNav']),
      salesBox: SalesBoxModel.fromJson(json['salesBox'])
    );
  }

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = Map<String, dynamic>();

    data['config'] = this.config;
    data['bannerList'] = this.bannerList;
    data['localNavList'] = this.localNavList;
    data['gridNav'] = this.gridNav;
    data['subNavList'] = this.subNavList;
    data['salesBox'] = this.salesBox;

    return data;
  }
}

/// 1. 首页数据模块configModel
/// @params {searchUrl} String
class ConfigModel {
  final String searchUrl;

  // 构造方法
  ConfigModel({this.searchUrl});

  // 工厂方法,
  factory ConfigModel.fromJson(Map<String, dynamic> json) {
    return ConfigModel(
      searchUrl: json['searchUrl']
    );
  }

  // 返回处理好的json数据
  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = Map<String, dynamic>();

    data['searchUrl'] = this.searchUrl;

    return data;
  }
}

/// 2. commonModel
/// @params {icon} String
/// @params {title} String
/// @params {url} String
/// @params {statusBarColor} String
/// @params {hideAppbar} bool
///
class CommonModel {
  final String icon;
  final String title;
  final String url;
  final String statusBarColor;
  final bool hideAppbar;

  CommonModel({this.icon, this.title, this.url, this.statusBarColor, this.hideAppbar});

  factory CommonModel.fromJson(Map<String, dynamic>json) {
    return CommonModel(
      icon: json['icon'],
      title: json['title'],
      url: json['url'],
      statusBarColor: json['statusBarColor'],
      hideAppbar: json['hideAppbar'],
    );
  }
  // 返回处理好的json数据
  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = Map<String, dynamic>();

    data['icon'] = this.icon;
    data['title'] = this.title;
    data['url'] = this.url;
    data['statusBarColor'] = this.statusBarColor;
    data['hideAppbar'] = this.hideAppbar;

    return data;
  }
}

/// 3. 首页网格卡片模型
/// @params {hotel} Object
/// @params {travel} Object
/// @params {flight} Object

class GridNavModel {
  final GridNavItemModel hotel;
  final GridNavItemModel travel;
  final GridNavItemModel flight;

  GridNavModel({this.hotel, this.travel, this.flight});

  factory GridNavModel.fromJson(Map<String,dynamic>json) {
    return json != null ?  GridNavModel(
      hotel: GridNavItemModel.fromJson(json['hotel']),
      flight: GridNavItemModel.fromJson(json['flight']),
      travel: GridNavItemModel.fromJson(json['travel']),
    ) : null ;
  }
  // 返回处理好的json数据
  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = Map<String, dynamic>();

    data['hotel'] = this.hotel;
    data['travel'] = this.travel;
    data['flight'] = this.flight;

    return data;
  }
}

/// 3-1 hotel 网格卡片的Obj拆分Model
/// @params {startColor} String
/// @params {endColor} String
/// @params {mainItem} Object CommonModel
/// @params {item1} Object CommonModel
/// @params {item2} Object CommonModel
/// @params {item3} Object CommonModel
/// @params {item4} Object CommonModel

class GridNavItemModel {
  final String startColor;
  final String endColor;
  final CommonModel mainItem;
  final CommonModel item1;
  final CommonModel item2;
  final CommonModel item3;
  final CommonModel item4;

  GridNavItemModel({this.startColor, this.endColor, this.mainItem, this.item1, this.item2, this.item3, this.item4});

  factory GridNavItemModel.fromJson(Map<String, dynamic>json) {
    return GridNavItemModel(
      startColor: json['startColor'],
      endColor: json['endColor'],
      mainItem: CommonModel.fromJson(json['mainItem']),
      item1: CommonModel.fromJson(json['item1']),
      item2: CommonModel.fromJson(json['item2']),
      item3: CommonModel.fromJson(json['item3']),
      item4: CommonModel.fromJson(json['item4']),
    );
  }

  // 返回处理好的json数据
  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = Map<String, dynamic>();

    data['startColor'] = this.startColor;
    data['endColor'] = this.endColor;
    data['mainItem'] = this.mainItem;
    data['item1'] = this.item1;
    data['item2'] = this.item2;
    data['item3'] = this.item3;
    data['item4'] = this.item4;

    return data;
  }
}

/// 4. SalesBoxModel
/// @params {icon} String
/// @params {moreUrl} String
//CommonModel bigCard1 | Object	|	NonNull
//CommonModel bigCard2 | Object	|	NonNull
//CommonModel smallCard1 | Object	|	NonNull
//CommonModel smallCard2 | Object	|	NonNull
//CommonModel smallCard3 | Object	|	NonNull
//CommonModel smallCard4 | Object	|	NonNull

class SalesBoxModel {
  final String icon;
  final String moreUrl;
  final CommonModel bigCard1;
  final CommonModel bigCard2;
  final CommonModel smallCard1;
  final CommonModel smallCard2;
  final CommonModel smallCard3;
  final CommonModel smallCard4;

  SalesBoxModel({this.icon, this.moreUrl, this.bigCard1, this.bigCard2, this.smallCard1, this.smallCard2, this.smallCard3, this.smallCard4});

  factory SalesBoxModel.fromJson(Map<String, dynamic >json) {
    return SalesBoxModel(
      icon: json['icon'],
      moreUrl: json['moreUrl'],
      bigCard1: CommonModel.fromJson(json['bigCard1']),
      bigCard2: CommonModel.fromJson(json['bigCard2']),
      smallCard1: CommonModel.fromJson(json['smallCard1']),
      smallCard2: CommonModel.fromJson(json['smallCard2']),
      smallCard3: CommonModel.fromJson(json['smallCard3']),
      smallCard4: CommonModel.fromJson(json['smallCard4']),
    );
  }

  // 转换为json
  Map<String, dynamic > toJson () {
    final Map<String, dynamic> data = Map<String, dynamic>();

    data['icon'] = this.icon;
    data['moreUrl'] = this.moreUrl;
    data['bigCard1'] = this.bigCard1;
    data['bigCard2'] = this.bigCard2;
    data['smallCard1'] = this.smallCard1;
    data['smallCard2'] = this.smallCard2;
    data['smallCard3'] = this.smallCard3;
    data['smallCard4'] = this.smallCard4;

    return data;
  }
}